package com.cjf.weather.weathercollection.config;

import com.cjf.weather.weathercollection.job.WeatherDataSynJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author cjf
 * @description 定时器
 * @create 2019-03-27 21:52
 */
@Configuration
public class QuartzConfiguration {

    // 多少秒刷新一次
    private static final int REFRESH_TIME = 1800;

    @Bean
    public JobDetail weatherDataSynJonDetail() {
        return JobBuilder.newJob(WeatherDataSynJob.class).storeDurably().build();
    }

    @Bean
    public Trigger weatherDataTrigger() {
        //每隔*秒做一次定时操作
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(REFRESH_TIME).repeatForever();
        return TriggerBuilder.newTrigger().forJob(weatherDataSynJonDetail()).withSchedule(simpleScheduleBuilder).build();
    }
}
